<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增菜品')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dish-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">菜品名称：</label>
                    <div class="col-sm-8">
                        <input name="dishName" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜品标题：</label>
                    <div class="col-sm-8">
                        <input name="dishTitle" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜品图片：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="hidden" name="dishPic" id="pic">
                        <a id="url"><img style="width: 90px;height: 90px"></a>
                        <input type="file" id="dishPic">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">菜品顺序：</label>
                    <div class="col-sm-8">
                        <input name="dishSort" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜品描述：</label>
                    <div class="col-sm-8">
                        <textarea id="dishContent" name="dishContent" class="form-control"></textarea>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">作者：</label>
                    <div class="col-sm-8">
                        <input name="author" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control"></textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "recipe/dish"
        $("#form-dish-add").validate({
            focusCleanup: true
        });

        // 上传文件
        $("#dishPic").change(function () {
            var data = new FormData();
            data.append("file", $("#dishPic")[0].files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    // alert(JSON.stringify(result))
                    if (result.code == web_status.SUCCESS) {
                        $("#url img").attr("src",result.fileName)
                        $("#pic").val(result.fileName)
                    }
                },
                error: function(error) {
                    alert("图片上传失败。");
                }
            });
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-dish-add').serialize());
            }
        }

        $(function() {
        });
    </script>
</body>
</html>